/**
 * @author Matan Mizrahi,Chen weissman
 * Introduction to computer science, assingment5
 * Date:2.1.2011
 */
public class LongMultiplication extends CompoundExpression{

    //*********************************Fields************************************//
	private static Expression[]  multEx;

	
    //*********************************Constructors******************************//
	public LongMultiplication(Expression[]  multEx){
		super(multEx);
	}

	
    //*********************************Behavior**********************************//
   



/**
 * 
 * Evaluates the expression given an assignment. 
 * @param assign the given assignment.
 * @return The value of this expression with respect
 * to the given assignment. Any variable in the expression 
 * which is not assigned with a value under the assignment
 * {@code assign} will be considered as a variable which
 * value is 0.
 */
public double evaluate(Assignment assign) {
	double ans=0;
	if (assign==null)
		throw new NullPointerException("LongMultiplication method evaluate got a null argument.");
	else
	for (int i=0;i<multEx.length;i=i+1)
		ans=ans*multEx[i].evaluate(assign);
	return ans;
}
public String getLastOperationSymbol() {
    return "PI";
}

/**
 * 
 * Derivative operation on Expression according to varName.
 * @param varName the name of the variable according to which
 * the expression is derived.
 * @return New expression representing the derivative of this expression.
 */
public Expression derivative(char varName){
	Expression[] derivedArr1=new Expression[multEx.length];
	Expression[] derivedArr2=null;
	LongMultiplication lm;
	LongSum ls;
	for (int i=0;i<multEx.length;i++){
		derivedArr2 = new Expression[multEx.length];
		for (int j=0;j<multEx.length;j++){
			if (i==j)
				derivedArr2[j]=multEx[j].derivative(varName);
			else
				derivedArr2[j]=multEx[j];
			}
		lm=new LongMultiplication(derivedArr2);
			derivedArr1[i]=lm;
		}
	ls = new LongSum(derivedArr1);
	return ls;
		}


/**
 * Replicating the invoking object.
 * 
 * @return a replicate of this object. The returned object has
 * to be a new object (with a different address than this
 * object), but equivalent to the this object under the 
 * application of the {@code equals(Object other)} method.
 */
public Expression replicate(){
 Expression[] ex1 = new Expression[multEx.length];
 for (int i=0;i<multEx.length;i++)
 {
	 ex1[i]=multEx[i];
 }
LongMultiplication lm= new LongMultiplication(ex1);
return lm;
}
}



